import request from '@/utils/request'
import { saveAs } from 'file-saver'

// 查询组件分类管理列表
export function listComponentCategory(query) {
    return request({
        url: '/admin-api/deploy/component-category/component-list',
        method: 'get',
        params: query
    })
}

// 获取所有组件
export function getAllComponent() {
    return request({
        url: '/admin-api/deploy/component-category/getAll',
        method: 'get'
    })
}

// 根据组件名称获取默认目录列表
export function getDefaultDirList(query) {
    return request({
        url: '/admin-api/deploy/component-deploy/getDefaultPath',
        method: 'get',
        params: query
    })
}

// 查询组件分类管理详细
export function getComponentCategory(query) {
    return request({
        url: '/admin-api/deploy/component-category/get',
        method: 'get',
        params: query
    })
}

// 新增组件分类管理
export function addComponentCategory(data) {
    return request({
        url: '/admin-api/deploy/component-category/create',
        method: 'post',
        data: data
    })
}

// 修改组件分类管理
export function updateComponentCategory(data) {
    return request({
        url: '/admin-api/deploy/component-category/update',
        method: 'put',
        data: data
    })
}

// 删除组件分类管理
export function delComponentCategory(data) {
    return request({
        url: '/admin-api/deploy/component-category/delete',
        method: 'delete',
        params: data
    })
}

// 下载文件
export function exportComponentCategory(data) {
    return request({
        url: '/admin-api/deploy/component-category/export-excel',
        method: 'get',
        params: data,
        responseType: 'blob',
    }).then(res => {
        const blob = new Blob([res], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8" })
        saveAs(blob, decodeURIComponent('组件分类记录.xlsx'))
    })
}